<?php
/**
 * Created by PhpStorm.
 * User: robot
 * Date: 2018-04-16
 * Time: 22:53
 */

namespace app\base;


use app\base\model\Artcomment;
use app\base\model\Article;
use app\base\model\Sort;
use app\base\model\User;
use think\Controller;
use think\Session;

class BaseController extends Controller
{

    protected function _initialize()
    {
        parent::_initialize();
            if (!Auth::isLogin()) {
                if ($this->request->module() === 'admin') {
                    $this->error('请登录', '/pub/index/login',['referurl'=>$this->request->url()]);
                }
                $this->assign('islog', '0');
            }else{
                if ($this->request->module() === 'admin'&&Session::get('user')['userstat'] != '1') {
                    $this->error('无权访问', '/',['referurl'=>$this->request->url()]);
                }
            $this->assign('nick', Session::get('user')['usernick']);
            $this->assign('stat', Session::get('user')['userstat']);
            $this->assign('islog', '1');




            }
        $this->assign('nav',Sort::all());
        $this->assign('articCount',(new Article())->count('articid'));
        $this->assign('userCount',(new User())->count('userid'));
        $this->assign('commentCount',(new Artcomment())->count('commentid'));

    }

}